/*
 *    Copyright 2008-2009 The PoCo Team
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package com.asemantics.poco;

import java.util.Date;
import java.util.TimeZone;

import lombok.Data;

/**
 * 
 * @author Simone Tripodi
 * @version $Id: DateTime.java 252 2009-12-20 01:07:31Z simone.tripodi@gmail.com $
 */
@Data
public final class DateTime implements Comparable<DateTime> {

    private Date date;

    private TimeZone timeZone;

    public DateTime() {
        this(new Date());
    }

    public DateTime(Date date) {
        this(date, TimeZone.getDefault());
    }

    public DateTime(Date date, TimeZone timeZone) {
        this.date = date;
        this.timeZone = timeZone;
    }

    public int compareTo(DateTime other) {
        final long thisTime = this.date.getTime();
        final long thisAbsoluteTime = thisTime - this.timeZone.getOffset(thisTime);
        final long otherTime = other.getDate().getTime();
        final long otherAbsoluteTime = otherTime - other.getTimeZone().getOffset(otherTime);
        return (int) (thisAbsoluteTime - otherAbsoluteTime);
    }

}
